using EnvDTE;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Assets.ValueProviders.Base;
using VSSDKAssist.Enums;
using System;

namespace VSSDKAssist.Recipes.FlavorProject.CreateFlavorProject
{
    /// <summary>
    /// Value provider for the template extension
    /// </summary>
    public class TemplateExtensionValueProvider : ValueProviderBase
    {
        #region Constants
        private const string TypeOfFlavorArgument = "TypeOfFlavorArgument";
        #endregion

        #region Fields
        private string typeOfFlavorArgument;
        #endregion

        public override bool OnBeforeActions(object currentValue, out object newValue)
        {
            newValue = null;

            if((currentValue == null) && (this.ExecutionStage != Stage.OnBeginRecipe))
            {
                FlavorProjectType type = (FlavorProjectType)Enum.Parse(typeof(FlavorProjectType), DictionaryService.GetValue(typeOfFlavorArgument).ToString());

                switch(type)
                {
                    case FlavorProjectType.CSharp:
                        newValue = "cs";
                        break;
                    case FlavorProjectType.VBasic:
                        newValue = "vb";
                        break;
                    default:
                        newValue = "cs";
                        break;
                }

                return true;
            }

            return false;
        }

        protected override void OnConfigure(System.Collections.Specialized.StringDictionary attributes)
        {
            if(attributes == null)
                throw new ArgumentNullException("attributes");

            if(attributes.ContainsKey(TypeOfFlavorArgument))
            {
                typeOfFlavorArgument = attributes[TypeOfFlavorArgument];
            }
        }
    }
}